﻿using GalleryCommon;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace GalleryWeb
{
    public partial class FolderControl : System.Web.UI.UserControl
    {
        Folder folder;
        public FolderControl(Folder f)
        {
            folder = f;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (folder!=null)
            {
                Title.Text = folder.Title;

                if (folder.Pictures != null)
                {
                    HtmlImage img;
                    if (folder.Pictures.Count>0)
                    {
                        img = new HtmlImage();
                        img.Width = 40;
                        img.Height = 40;
                        img.Src = "data: image / png; base64," + Convert.ToBase64String(folder.Pictures[0].PictureFile);

                        cell1.Controls.Add(img);
                    }
                    if (folder.Pictures.Count > 1)
                    {
                        img = new HtmlImage();
                        img.Width = 40;
                        img.Height = 40;
                        img.Src = "data: image / png; base64," + Convert.ToBase64String(folder.Pictures[0].PictureFile);

                        cell2.Controls.Add(img);
                    }
                    if (folder.Pictures.Count > 2)
                    {
                        img = new HtmlImage();
                        img.Width = 40;
                        img.Height = 40;
                        img.Src = "data: image / png; base64," + Convert.ToBase64String(folder.Pictures[0].PictureFile);

                        cell3.Controls.Add(img);
                    }
                    if (folder.Pictures.Count > 3)
                    {
                        img = new HtmlImage();
                        img.Width = 40;
                        img.Height = 40;
                        img.Src = "data: image / png; base64," + Convert.ToBase64String(folder.Pictures[0].PictureFile);

                        cell4.Controls.Add(img);
                    }
                }

                Date.Text = folder.Date.Year.ToString() + '.' + folder.Date.Month.ToString() + '.' + folder.Date.Day.ToString();
            }
        }
        




        protected void DeleteImages(string fn1, string fn2, string fn3, string fn4)
        {
            try
            {
                if (fn1 != null)
                {
                    File.Delete(fn1);
                }
                if (fn2 != null)
                {
                    File.Delete(fn2);
                }
                if (fn3 != null)
                {
                    File.Delete(fn3);
                }
                if (fn4 != null)
                {
                    File.Delete(fn4);
                }
            }
            catch(Exception) { }
        }        
    }
}